using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Edit : System.Web.UI.UserControl
{
    private int loadTestRunId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        //get the run id.  If it does not exist go back to default page
        string runID = (string)Session["RunId"];
        if (runID != null && runID.Length > 0)
        {
            loadTestRunId = Convert.ToInt32(runID);
        }
        else
        {
            Session["RunId"] = null;
            Response.Redirect("home.aspx", false);
        }

        //create DBHelper
        DBHelper dbHelper = new DBHelper();

        //load the form
        string loadTestName = null;        
        string description = null;
        string comment = null;
        dbHelper.ReadRecord(loadTestRunId, ref loadTestName, ref description, ref comment);

        lblLoadTestName.Text = loadTestName;        
        TextBoxDescription.Text = description;
        TextBoxComment.Text = comment;
    }


    protected void ButtonClear_Click(object sender, System.EventArgs e)
    {        
        TextBoxDescription.Text = string.Empty;
        TextBoxComment.Text = string.Empty;
    }

    protected void ButtonCancel_Click(object sender, System.EventArgs e)
    {
        Session["RunId"] = null;
        Response.Redirect("Default.aspx", false);
    }

    protected void Update_Click(object sender, System.EventArgs e)
    {
        //save the data back to the database
        DBHelper dbHelper = new DBHelper();

        dbHelper.UpdateRecord(
            loadTestRunId,            
            TextBoxDescription.Text,
            TextBoxComment.Text);
        Session["RunId"] = null;
        Response.Redirect("Default.aspx", false);
    }
}
